<?php

namespace app\admin\model;

class Feedback extends \app\common\model\Feedback
{
    /**
     * 列表
     * @param $where
     * @return array
     * @throws \think\exception\DbException
     */
    public static function getList($where)
    {
        $sql = static::field('f.id, o.nickname, f.content, f.phone, f.deal_status, f.deal_time, f.create_time')
            ->alias('f')
            ->join('oauth o', 'f.oauth_id = o.id', 'INNER');

        if ($where) {
            $sql->where($where);
        }

        $data = $sql->paginate(null, false, ['query' => request()->param()]);

        $model = $data->each(function ($item, $key) {
            $item['deal_time'] = get_datetime($item['deal_time']);
            $item['create_time'] = get_datetime($item['create_time']);
            $item['dealStatusText'] = self::attributes('deal_status', $item['deal_status']);
            return $item;
        });

        // 获取总记录数
        $count = $model->total();
        return [
            'model' => $model,
            'count' => $count
        ];
    }

    /**
     * 修改状态
     * @param $id
     */
    public static function dealOne($id)
    {
        $model = static::get($id);
        if ($model) {
            $model->deal_status = ($model->deal_status == self::DEAL_NO) ? self::DEAL_YES : self::DEAL_NO;
            $model->deal_time = time();
            $model->save();
        }
    }
}